import React, { Component } from 'react';
import { Button, Modal, Select, Form, Row, Col, Input, Radio, Table, DatePicker, notification } from 'antd';
import BaseComponent from '@/components/BaseComponent';
import { connect } from 'dva';
import request from 'umi-request';
import Index from '@/pages/Company/warehouse/list';

@connect(({ user, }) => ({
  // data: risk.riskData,
  currentUser: user.currentUser,
}))
@Form.create()
class PhysicalExamination extends BaseComponent {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
      form: {},
      yesOrNo: [
        { label: '无', value: '1' },
        { label: '有', value: '2' },
      ],
      whether: [
        { label: '否', value: '1' },
        { label: '是', value: '2' },
      ],
      testResult: [
        { label: '阴', value: '1' },
        { label: '阳', value: '2' },
      ],
    };
  }

  showModal = () => {
    // 体检表详情
    request("/api/cdcerservice/v1/cerSysteminitImportInfo/getPhysicalExaminationByInfoId?infoId=" + this.props.record.id, {
      method: "GET",
    }).then((resp) => {
      if (resp.success && resp.data.content !== undefined) {
        this.setState({
          visible: true,
          form: JSON.parse(resp.data.content),
        });
      } else {
        this.setState({
          visible: true,
          form: {
            name: this.props.record.name,
            screeningId: this.props.record.screening_id,
            phone: this.props.record.phone,
          },
        });
      }
    })
  };

  handleOk = () => {
    request("/api/cdcerservice/v1/cerSysteminitImportInfo/editPhysicalExaminationInfo", {
      method: "POST",
      requestType: 'form',
      data: {
        infoId: this.props.record.id,
        name: this.state.form.name,
        idCard: this.state.form.idCard,
        screeningId: this.props.record.screening_id,
        phone: this.state.form.phone,
        content: JSON.stringify(this.state.form),
      }
    }).then((resp) => {
      notification.open({
        message: resp.message
      })
      this.setState({
        visible: false,
      });
      this.props.getDataByPage({});
    })
  };

  handleCancel = () => {
    this.setState({
      visible: false,
    });
  };

  handleChange = e => {
    const { name, value } = e.target;
    this.setState(params => ({
      form: {
        ...params.form,
        [name]: value,
      },
    }));
  };

  aspirinDateChange = (date, dateString) => {
    this.setState((params) => ({
      form: {
        ...params.form,
        aspirinDate: dateString
      }
    }));
  }

  gastricAntacidsDateChange = (date, dateString) => {
    this.setState((params) => ({
      form: {
        ...params.form,
        aspirinDate: dateString
      }
    }));
  }

  render() {
    const { visible } = this.state;

    const { record } = this.props;


    const { getFieldDecorator } = this.props.form


    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
    };

    const color = record.physicalExaminationInfoId ? '#67c23a' : '#e6a23c';

    return (
      <div>
        <Button
          type="primary"
          style={{ marginLeft: '10px', background: color, borderColor: color }}
          onClick={this.showModal}
        >
          体检表
        </Button>
        <Modal
          title="临床体检表"
          visible={visible}
          onOk={this.handleOk}
          onCancel={this.handleCancel}
          width={1500}
        >
          <Form {...formItemLayout}>
            <Row gutter={16}   >
              <Col span={6}  >
                {/* <Form.Item style={{ width: "100%" }}>
                  <Row style={{ width: "100%" }}>
                    <Col span={8}  >姓名</Col>
                    <Col span={16}>
                      <Input
                        placeholder="姓名"
                        value={this.state.form.name}
                        onChange={this.handleChange}
                        disabled
                      />
                    </Col>
                  </Row>


                </Form.Item> */}

                <Row style={{ display: "flex" }} gutter={2}>

                  <Col span={8} style={{ textAlign: "end", alignSelf: "center" }}>姓名:</Col>
                  <Col span={16}>
                    {
                      getFieldDecorator("name",
                        {
                          initValue:record.name,
                          rules: [
                            {
                              required: true,
                              message: '请输入姓名',
                            }
                          ]
                        },
                      )(<Input
                        placeholder="姓名"
                        // value={this.state.form.name}
                        onChange={this.handleChange}
                        disabled
                      />)

                    }

                  </Col>

                </Row>

              </Col>
              <Col span={6}>
                {/* <Form.Item label="身份证">
                  <Input
                    name="idCard"
                    placeholder="身份证"
                    value={this.state.form.idCard}
                    onChange={this.handleChange}
                  />
                </Form.Item> */}

                <Row style={{ display: "flex" }} gutter={2}>

                  <Col span={8} style={{ textAlign: "end", alignSelf: "center" }}>身份证号:</Col>
                  <Col span={16}>
                    {
                      getFieldDecorator("idCard",
                        {
                          rules: [
                            {
                              required: true,
                              message: '请输入身份证号',
                            }
                          ]
                        },
                      )(<Input
                        placeholder="请输入身份证"
                        // value={this.state.form.idCard}
                        onChange={this.handleChange}
                        
                      />)

                    }

                  </Col>

                </Row>
              </Col>
              <Col span={6}>
                <Form.Item label="调查对象ID号">
                  <Input
                    placeholder="调查对象ID号"
                    value={this.state.form.screeningId}
                    onChange={this.handleChange}
                    disabled
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="电话">
                  <Input
                    name="phone"
                    placeholder="电话"
                    value={this.state.form.phone}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
            </Row>

            <h3>一般情况</h3>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="身高(cm)">
                  <Input
                    name="height"
                    placeholder="cm"
                    value={this.state.form.height}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="体重(kg)">
                  <Input
                    placeholder="Kg"
                    name="weight"
                    value={this.state.form.weight}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
              <Col span={12} style={{ display: 'grid', gridTemplateColumns: '2fr auto 2fr', gridColumnGap: '8px' }}>
                <Form.Item label="血压(mmHg)">
                  <Input
                    name="bloodPressure1"
                    value={this.state.form.bloodPressure1}
                    onChange={this.handleChange}
                  />
                </Form.Item>
                <span style={{ gridColumn: '2', display: 'flex', justifyContent: 'center', alignItems: 'center', marginTop: 'auto', marginBottom: 'auto' }}>/</span>
                <Form.Item>
                  <Input
                    name="bloodPressure2"
                    value={this.state.form.bloodPressure2}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
            </Row>

            <h3>上消化道症状</h3>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="上消化道症状">
                  <Radio.Group
                    name='upperGastrointestinalSymptoms'
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.upperGastrointestinalSymptoms}
                  />
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="上腹胀">
                  <Radio.Group
                    name="upperAbdominalDistention"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.upperAbdominalDistention}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="upperAbdominalDistentionDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.upperAbdominalDistentionDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.upperAbdominalDistention !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="烧心">
                  <Radio.Group
                    name="heartburn"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.heartburn}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input name="heartburnDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.heartburnDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.heartburn !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="反酸">
                  <Radio.Group name="acidReflux"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.acidReflux}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="acidRefluxDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.acidRefluxDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.acidReflux !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="恶心">
                  <Radio.Group
                    name="disgusting"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.disgusting}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="disgustingDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.disgustingDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.disgusting !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="打嗝">
                  <Radio.Group
                    name="burp"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.burp}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="burpDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.burpDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.burp !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="嗳气">
                  <Radio.Group
                    name="belch"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.belch}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="belchDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.belchDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.belch !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="食欲不振">
                  <Radio.Group
                    name="lossOfAppetite"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.lossOfAppetite}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="lossOfAppetiteDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.lossOfAppetiteDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.lossOfAppetite !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="胃疼">
                  <Radio.Group
                    name="stomachPain"
                    options={this.state.yesOrNo}
                    onChange={this.handleChange}
                    value={this.state.form.stomachPain}
                    disabled={this.state.form.upperGastrointestinalSymptoms !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="stomachPainDays"
                    placeholder="请输入持续时间/天"
                    value={this.state.form.stomachPainDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.stomachPain !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <h3>胃镜或钡餐造影</h3>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="胃镜或钡餐造影">
                  <Radio.Group
                    name="gastroscopyOrBariumSwallow"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.gastroscopyOrBariumSwallow}
                  />
                </Form.Item>
              </Col>
            </Row>

            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="胃镜">
                  <Radio.Group
                    name="gastroscope"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.gastroscope}
                    disabled={this.state.form.gastroscopyOrBariumSwallow !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="诊断结果">
                  <Input
                    name="gastroscopeResult"
                    placeholder="请输入诊断结果"
                    value={this.state.form.gastroscopeResult}
                    onChange={this.handleChange}
                    disabled={this.state.form.gastroscope !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="钡餐造影">
                  <Radio.Group
                    name="bariumSwallow"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.bariumSwallow}
                    disabled={this.state.form.gastroscopyOrBariumSwallow !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="诊断结果">
                  <Input
                    name="bariumSwallowResult"
                    placeholder="请输入诊断结果"
                    value={this.state.form.bariumSwallowResult}
                    onChange={this.handleChange}
                    disabled={this.state.form.bariumSwallow !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>

            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="容易出血而不容易止血">
                  <Radio.Group
                    name="haemorrhage"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.haemorrhage}
                  />
                </Form.Item>
              </Col>
            </Row>
            <h3>是否服用过以下药物</h3>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="是否服用过以下药物">
                  <Radio.Group
                    name="medications"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.medications}
                  />
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="阿司匹林等">
                  <Radio.Group
                    name="aspirin"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.aspirin}
                    disabled={this.state.form.medications !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="服用日期">
                  <DatePicker
                    placeholder="服用日期"
                    onChange={this.aspirinDateChange}
                    disabled={this.state.form.aspirin !== '2'}
                  />

                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="aspirinDays"
                    placeholder="持续时间/天"
                    value={this.state.form.aspirinDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.aspirin !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="胃抑酸药">
                  <Radio.Group
                    name="gastricAntacids"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.gastricAntacids}
                    disabled={this.state.form.medications !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="服用日期">
                  <DatePicker
                    name="gastricAntacidsDate"
                    placeholder="服用日期"
                    onChange={this.gastricAntacidsDateChange}
                    disabled={this.state.form.gastricAntacids !== '2'}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="持续时间(天)">
                  <Input
                    name="gastricAntacidsDays"
                    placeholder="持续时间/天"
                    value={this.state.form.gastricAntacidsDays}
                    onChange={this.handleChange}
                    disabled={this.state.form.gastricAntacids !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <h3>血液感染检查</h3>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="血液感染四项检查">
                  <Radio.Group
                    name="fourTestsForBloodInfections"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.fourTestsForBloodInfections}
                  />
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="乙肝">
                  <Radio.Group
                    name="hepatitisB"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.hepatitisB}
                    disabled={this.state.form.fourTestsForBloodInfections !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="检测结果">
                  <Radio.Group
                    name="hepatitisBTestResult"
                    options={this.state.testResult}
                    onChange={this.handleChange}
                    value={this.state.form.hepatitisBTestResult}
                    disabled={this.state.form.hepatitisB !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="丙肝">
                  <Radio.Group
                    name="hepatitisC"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.hepatitisC}
                    disabled={this.state.form.fourTestsForBloodInfections !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="检测结果">
                  <Radio.Group
                    name="hepatitisCTestResult"
                    options={this.state.testResult}
                    onChange={this.handleChange}
                    value={this.state.form.hepatitisCTestResult}
                    disabled={this.state.form.hepatitisC !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="艾滋病">
                  <Radio.Group
                    name="aids"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.aids}
                    disabled={this.state.form.fourTestsForBloodInfections !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="检测结果">
                  <Radio.Group
                    name="aidsTestResult"
                    options={this.state.testResult}
                    onChange={this.handleChange}
                    value={this.state.form.aidsTestResult}
                    disabled={this.state.form.aids !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="梅毒">
                  <Radio.Group
                    name="syphilis"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.syphilis}
                    disabled={this.state.form.fourTestsForBloodInfections !== '2'}
                  />
                </Form.Item>
              </Col>

              <Col span={6}>
                <Form.Item label="检测结果">
                  <Radio.Group
                    name="syphilisTestResult"
                    options={this.state.testResult}
                    onChange={this.handleChange}
                    value={this.state.form.syphilisTestResult}
                    disabled={this.state.form.syphilis !== '2'}
                  />
                </Form.Item>
              </Col>

            </Row>
            <h3>其他检查</h3>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="以下检查是否正常">
                  <Radio.Group
                    name="theExaminationIsNormal"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.theExaminationIsNormal}
                  />
                </Form.Item>
              </Col>
            </Row>
            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="心脏">
                  <Radio.Group
                    name="heart"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.heart}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="说明">
                  <Input
                    name="heartShows"
                    placeholder="请输入说明"
                    value={this.state.form.heartShows}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="肝">
                  <Radio.Group
                    name="liver"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.liver}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="说明">
                  <Input
                    name="liverShows"
                    placeholder="请输入说明"
                    value={this.state.form.liverShows}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
            </Row>

            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="肺">
                  <Radio.Group
                    name="lungs"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.lungs}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="说明">
                  <Input
                    name="lungsShows"
                    placeholder="请输入说明"
                    value={this.state.form.lungsShows}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="肾功能">
                  <Radio.Group
                    name="kidney"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.kidney}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="说明">
                  <Input
                    name="kidneyShows"
                    placeholder="请输入说明"
                    value={this.state.form.kidneyShows}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
            </Row>

            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="巩膜">
                  <Radio.Group
                    name="sclera"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.sclera}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="说明">
                  <Input
                    name="scleraShows"
                    placeholder="请输入说明"
                    value={this.state.form.scleraShows}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
            </Row>

            <Row gutter={16}>
              <Col span={6}>
                <Form.Item label="是否符合胃镜检查条件">
                  <Radio.Group
                    name="gastroscopy"
                    options={this.state.whether}
                    onChange={this.handleChange}
                    value={this.state.form.gastroscopy}
                  />
                </Form.Item>
              </Col>
              <Col span={6}>
                <Form.Item label="体检医生">
                  <Input
                    name="medicalExaminer"
                    placeholder="请输入体检医生"
                    value={this.state.form.medicalExaminer}
                    onChange={this.handleChange}
                  />
                </Form.Item>
              </Col>
            </Row>
          </Form>
        </Modal >
      </div >
    );
  }
}



export default PhysicalExamination;